﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Collections.ObjectModel;
using System.Windows.Threading;
using System.Collections;
using System.ComponentModel;
using System.Windows.Media;
using System.Windows;
using System.Windows.Documents;

using System.IO;
using System.Drawing.Imaging;
using System.Windows.Media.Imaging;

namespace WGM_Client_Net35V2
{
    public static class HelperFunctions
    {
        public static Color GetNewColour(System.Drawing.Color colour)
        {
            return Color.FromRgb(colour.R, colour.G, colour.B);
        }
        public static Color GetNewColour(int colourInt)
        {
            System.Drawing.Color oldColour = System.Drawing.Color.FromArgb(colourInt);
            return Color.FromRgb(oldColour.R, oldColour.G, oldColour.B);
        }
        public static Color GetNewColour(WGM_Svc.UserOptions uo)
        {
            return Color.FromRgb((byte)uo.FontColourR, (byte)uo.FontColourG, (byte)uo.FontColourB);

        }
        public static FontWeight GetFontWeight(int oldWeight)
        {
            switch (oldWeight)
            {
                case 0:
                    return FontWeights.Normal;
                default:
                    return FontWeights.Normal;
            }
        }
        public static FontStyle GetFontStyle(int oldStyle)
        {
            switch (oldStyle)
            {
                case 0:
                    return FontStyles.Normal;
                default:
                    return FontStyles.Normal;
            }
        }
        public static string GetIntroString(WGM_Svc.UserOptions clientData)
        {

            string retVal = clientData.DisplayName;
            if (clientData.DisplayName.Trim() == "")
                retVal = clientData.UserName;

            if (WGM_Client_Net35V2.Properties.Settings.Default.DisplayUserName == true)
                retVal += " (" + clientData.UserName + ")";
            return retVal;
        }
        public static string GetContactTitle(WGM_Svc.UserOptions clientData)
        {
            string retVal = clientData.DisplayName;
            if (clientData.DisplayName.Trim() == "")
                retVal = clientData.UserName;
            if (clientData.UserStatus != null && clientData.UserStatus.Trim() != "")
                retVal += " - " + clientData.UserStatus;

            return retVal;
        }

        public static string GetCLToolTip(WGM_Svc.UserOptions clientData)
        {
            string retVal = clientData.DisplayName;
            if (clientData.UserStatus != null && clientData.UserStatus.Trim() != "")
                retVal += " - " + clientData.UserStatus;

            retVal += " (" + clientData.UserName + ")";

            return retVal;
        }
        public static bool IsMessageValid(WGM_Svc.WGMMessage message, DateTime logonTime, TimeSpan serverTimeOffset)
        {
            if (message.TimeStamp < logonTime)
                return false;


            return true;
        }
        public static System.Drawing.Image ByteArrayToImage(byte[] byteArrayIn)
        {
            MemoryStream ms = new MemoryStream(byteArrayIn);
            System.Drawing.Image returnImage = System.Drawing.Image.FromStream(ms);
            return returnImage;
        }
        public static byte[] ImageToByteArray(System.Drawing.Image imageIn, ImageFormat format)
        {
            MemoryStream ms = new MemoryStream();
            imageIn.Save(ms, format);
            return ms.ToArray();
        }
        public static BitmapImage GetBitmapFromImage(System.Drawing.Image imageIn)
        {
            // ImageSource ...

            BitmapImage bi = new BitmapImage();
            bi.BeginInit();
            MemoryStream ms = new MemoryStream();
            // Save to a memory stream...
            imageIn.Save(ms, ImageFormat.Bmp);
            // Rewind the stream...
            ms.Seek(0, SeekOrigin.Begin);
            // Tell the WPF image to use this stream...
            bi.StreamSource = ms;
            bi.EndInit();

            return bi;
        }
        public static bool AreStringsEqual(string strA, string strB, bool ignoreCase)
        {
            if (String.Compare(strA.Trim(), strB.Trim(), ignoreCase) == 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
    }



}
